<?php
namespace App\Http\Controllers\Api\v1\Auth;


use App\Tools\Base\Auth;
use Illuminate\Support\Facades\Input;
use DB;

class BaseController extends Auth
{
   /* public function __construct()
    {
        if(!defined('IS_ACCESS_TOKEN_CHECKED'))
        {
            // 接口调用验证
            $check = $this->checkAuth();

            if($check['code'] != 200)
            {
                echo json_encode($check);
                exit;
            }
        }
    }*/

    protected function checkAuth()
    {
        $access_token =privDecrypt(Input::get('access_token'));

        if(!$access_token)
        {
            return ['code'=>10107,'msg'=>'访问凭证不存在'];
        }

        $data = DB::table('appid') -> where(["app_accesstoken"=>$access_token]) -> first();

        if(empty($data) || $data['app_expire'] + $data['app_gettime'] < time())
        {
            return ['code'=>10108,'msg'=>'访问凭证过期'];
        }

        if($data['app_status'] != 1)
        {
            return ['code'=>10109,'msg'=>'禁止访问'];
        }
        define('IS_ACCESS_TOKEN_CHECKED',true);

        return ['code'=>200,'msg'=>'成功'];
    }

}